/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.servicelayer.gamelogic.resolver;

/**
 * Class used for getting distance between two Tiles
 *
 * @author Jakub Kutil
 */
public class TravelDistanceResolver {

    /**
     * Gets distance between two Tiles
     *
     * @param x1 value of x-coordinate of first Tile
     * @param y1 value of y-coordinate of first Tile
     * @param x2 value of x-coordinate of second Tile
     * @param y2 value of y-coordinate of second Tile
     * 
     * @return distance between two Tiles
     */
    public double calculateDistance(int x1, int y1, int x2, int y2) {
        double diffX = 0;
        double diffY = 0;

        if (x1 >= 0 && x2 >= 0) {
            diffX = Math.abs(x1 - x2);
        }
        if (y1 >= 0 && y2 >= 0) {
            diffY = Math.abs(y1 - y2);
        }

        if (x1 < 0 && x2 < 0) {
            diffX = Math.abs(x1 + x2);
        }
        if (y1 < 0 && y2 < 0) {
            diffY = Math.abs(y1 + y2);
        }

        if (x1 <= 0 && x2 >= 0 || x1 > 0 && x2 < 0) {
            diffX = Math.abs(x1) + Math.abs(x2) - 1;
        }
        if (y1 <= 0 && y2 >= 0 || y1 > 0 && y2 < 0) {
            diffY = Math.abs(y1) + Math.abs(y2) - 1;
        }

        return Math.ceil(Math.sqrt((diffX * diffX + diffY * diffY)));

    }
}
